package cn.zxl.spring.holiday.job.web.controller.dictionary;


import cn.zxl.spring.holiday.job.domain.DictData;
import cn.zxl.spring.holiday.job.domain.DictType;
import cn.zxl.spring.holiday.job.service.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 字典类型表 前端控制器
 * </p>
 *
 * @author bofeifei
 * @since 2021-10-06
 */
@Controller
@RequestMapping("/systemDictionary")
public class DictTypeController {

    @Autowired
    private DictTypeService typeService;

    @RequestMapping("list")
    public String list(Model model) {
        List<DictType> query = typeService.list(null);
        model.addAttribute("dictTypeList",query);
        return "dicttype/view";
    }

    @RequestMapping("/edit/{dictId}")
    public String edit(@PathVariable("dictId")String dictId, Model model) {
        if (dictId != null) {
            DictType dictType = typeService.getById(Long.parseLong(dictId));
            model.addAttribute("dictType", dictType);
        }
        return "dicttype/edit";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(DictType dictType) {
        if (dictType.getDictId() != null) {
            typeService.updateById(dictType);
            return "redirect:/systemDictionary/list";
        }
        typeService.save(dictType);
        return "redirect:/systemDictionary/list";
    }

    @RequestMapping("/add")
    public String add(Model model) {
        return "dicttype/edit";
    }
}

